﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.Skins;
using RTSoft.Entity;
using RTSoft.SoureCode.Entity;
using RTSoft.Modules;
using System.Configuration;

namespace RTSoft
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
        }
        String nodeName = "";
        private void bbtnSignOut_ItemClick(object sender, ItemClickEventArgs e)
        {
            Boolean rs = false;
            rs = Library.ShowQuestionMessage("Bạn có muốn đăng xuất không?");
            if (rs == true)
            {
                this.Hide();
                frmLogin frm = new frmLogin();
                frm.ShowDialog();
            }
        }

        private void bsiExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
           
            DevExpress.Skins.SkinManager.EnableFormSkins();
            this.defaultLookAndFeel1.LookAndFeel.SkinName = ConfigurationManager.AppSettings.Get("Skin");

            String[] lstSkin = new String[]{"Caramel","Money Twins","Lilian","The Asphalt World","iMaginary","Black","Blue","Coffee","Liquid Sky","London Liquid Sky","Glass Oceans","Stardust","Xmas 2008 Blue","Valentine","McSkin","Summer 2008","Pumpkin","Dark Slide","Sharp Plus","Sharp","Seven Classic","Seven","High Contrast","Foggy","Darkroom","Springtime","Office 2007 Blue","Office 2007 Black","Office 2007 Pink","Office 2007 Green","Office 2007 Silver"};

            foreach (SkinContainer cnt in SkinManager.Default.Skins)
            {
                //comboBoxEdit1.Properties.Items.Add(cnt.SkinName);
                BarButtonItem bbi = new BarButtonItem();
                bbi.Caption = cnt.SkinName;
                bbi.ItemClick += SelectSkinChange;
                bsiSkin.AddItem(bbi);
            }
            barUser.Caption = RTValidate.RTUser;
            // phân quyền
            /* 1 - Administrator
             * 2 - Nhân Viên
             * 3 - Khách Hàng - chỉ xem
             */
            if (RTValidate.RTJobTittle != 1)
            {
                treeView1.Nodes[7].Remove();
            }

        }
        //Đổi skin cho form
        private void SelectSkinChange(Object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.defaultLookAndFeel1.LookAndFeel.SkinName = e.Item.Caption;
            ConfigurationManager.AppSettings.Set("Skin", e.Item.Caption);
        }


        // Hiển thị form con
        public void HienThiForm(Form frm)
        {
            try
            {
                foreach (Form f in this.MdiChildren)
                {
                    if (f.Name == frm.Name)
                    {
                        f.Activate();
                        return;
                    }

                }
                frm.MdiParent = this;
                frm.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        public void ShowForm(Form frm)
        {

            try
            {
                foreach (Form f in this.MdiChildren)
                {
                    if (f.Name == frm.Name)
                    {
                        f.Close();
                        break; // TODO: might not be correct. Was : Exit For
                    }

                }
                frm.MdiParent = this;
                frm.Show();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            nodeName = e.Node.Name;
        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            String name = nodeName;
            if (name == "")
                return;
            switch (name)
            {
                //****Chức năng chính
                case "cCustomer":
                    frmKhachHang frmcCustomer = new frmKhachHang();
                    this.HienThiForm(frmcCustomer);
                    break;
                case "cItem":
                    frmMatHang frmcItem = new frmMatHang();
                    this.HienThiForm(frmcItem);
                    break;
                case "cImportItem":
                    frmNhapHang frmcImportItem = new frmNhapHang();
                    this.HienThiForm(frmcImportItem);
                    break;
                case "cExportItem":
                    frmXuatHang frmcExportItem = new frmXuatHang();
                    this.HienThiForm(frmcExportItem);
                    break;

                //****** Báo cáo
                case "cReportImportItem":
                    frmTKHangHoa frmcReportImportItem = new frmTKHangHoa();
                    this.HienThiForm(frmcReportImportItem);
                    break;
                case "cReportAmount":
                    frmDoanhThu frmcDoanhThu = new frmDoanhThu();
                    this.HienThiForm(frmcDoanhThu);
                    break;

                //****** Cài đặt danh mục
                case "cItemGroup":
                    frmLoaiHang frmcItemGroup = new frmLoaiHang();
                    this.HienThiForm(frmcItemGroup);
                    break;
                case "cSalary":
                    frmLuong frmcSalary = new frmLuong();
                    this.HienThiForm(frmcSalary);
                    break;
                case "cLevel":
                    frmBac frmcLevel = new frmBac();
                    this.HienThiForm(frmcLevel);
                    break;
                case "cValid":
                    frmHeSo frmcValid = new frmHeSo();
                    this.HienThiForm(frmcValid);
                    break;
                case "cRole":
                    frmQuyen frmcRole = new frmQuyen();
                    this.HienThiForm(frmcRole);
                    break;
                case "cJobTittle":
                    frmNhomQuyen frmcRoleGroup = new frmNhomQuyen();
                    this.HienThiForm(frmcRoleGroup);
                    break;
                case "cEmployee":
                    frmNhanVien frmcEmp = new frmNhanVien();
                    this.HienThiForm(frmcEmp);
                    break;
                case "cNational":
                    frmXuatXu frmcNation = new frmXuatXu();
                    this.HienThiForm(frmcNation);
                    break;
                case "cBrand":
                    frmNhaSX frmcBrand = new frmNhaSX();
                    this.HienThiForm(frmcBrand);
                    break;
                case "cPrice":
                    frmDonGiaBan frmcPrice = new frmDonGiaBan();
                    this.HienThiForm(frmcPrice);
                    break;
                case "cDate":
                    frmNgay frmcDate = new frmNgay();
                    this.HienThiForm(frmcDate);
                    break;
                //Nhật ký
                case "cEntryImportItem":
                    frmNhatKyNhap frmcEntryImport = new frmNhatKyNhap();
                    this.HienThiForm(frmcEntryImport);
                    break;
                case "cEntryExportItem":
                    frmNhatKyXuat1 frmcEntryExport = new frmNhatKyXuat1();
                    this.HienThiForm(frmcEntryExport);
                    break;
            }
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        public void ShowReport()
        {
            frmShowReport frm = new frmShowReport();
            this.HienThiForm(frm);
        }

        private void bsiConfig_ItemClick(object sender, ItemClickEventArgs e)
        {
            bbtnSignOut_ItemClick(null, null);
        }

        private void ribbon_Click(object sender, EventArgs e)
        {

        }

       
    }
}